<!-- 培训申请列表页 -->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据来源">
              <j-dict-select-tag
                placeholder="请选择单据来源"
                @input="handleDocumentSource"
                v-model="queryParam.permissionType"
                dictCode="permission_type" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 3">
            <a-form-item label="选择部门">
              <J-select-multiple
                placeholder="请选择选择部门"
                :options="getDepartName"
                showId="id"
                v-model="queryParam.deptIds" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 4">
            <a-form-item label="选择团队">
              <J-select-multiple
                placeholder="请选择选择团队"
                :options="getTeamName"
                showId="id"
                v-model="queryParam.teamIds" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号" class="form-item">
              <j-input placeholder="请输入单据编号" v-model="queryParam.billNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType != 3">
            <a-form-item label="申请部门" class="form-item">
              <j-select-depart placeholder="请选择申请部门" v-model="queryParam.applyDeptId" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item
              label="申请人"
              :wrapperCol="{
                xs: { span: 24 },
                sm: { span: 12 },
              }">
              <select-user-by-dep placeholder="请选择申请人" :multi="false" v-model="queryParam.handlerId" />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button
        @click="handleAdd"
        type="primary"
        icon="plus"
        :disabled="isDisabledAuth('erpPurchaseApplyInvitation:add')">新增</a-button>
      <a-button
        @click="handleChange"
        type="primary"
        icon="plus">变更</a-button>
      <a-button @click="handleRevoked" type="primary">作废</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('招标采购申请单')" :disabled="isDisabledAuth('erpPurchaseApplyInvitation:export')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpPurchaseApplyInvitation:import')">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpPurchaseApplyInvitation:delete')"><a-icon
            type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style="iconStyle" /></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ getCheckboxProps: getCheckboxProps, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="billNo" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <span slot="notify" slot-scope="text, record">
          <a-icon
            title="催办提醒"
            v-if="record.taskUrge"
            theme="twoTone"
            twoToneColor="#eb2f96"
            @click="taskNotifyMe(flowCode, record.id)"
            type="notification" />
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <p slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </p>

        <span slot="action" slot-scope="text, record">
          <template v-if="record.bpmStatus === '1'">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpPurchaseApplyInvitation:edit')" />
            <a-divider type="vertical" />
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpPurchaseApplyInvitation:delete')" />
            </a-popconfirm>
            <!-- <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="beginProcess(record)" :disabled="isDisabledAuth('erpPurchaseApplyInvitation:startProcess')">发起流程</a-button> -->
          </template>
          <template v-else-if="showBtn(record.bpmStatus) && queryParam.bizTaskType == '1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical" />
          </template>
          <template v-else-if="queryParam.bizTaskType == '2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode, record.id)">催办</a-button>
            <a-divider type="vertical" />
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
              <a-button
                type="primary"
                size="small"
                :disabled="isDisabledAuth('erpPurchaseApplyInvitation:invalidProcess')">
                作废流程
              </a-button>
            </a-popconfirm>
            <a-divider type="vertical" />
          </template>
          <template v-if="record.bpmStatus !== '1'">
            <a-button
              type="primary"
              size="small"
              @click="handleTrack(record)"
              :disabled="isDisabledAuth('erpPurchaseApplyInvitation:viewTrack')">审批进度</a-button>
          </template>
        </span>

      </a-table>
    </div>

    <ErpHrTrainingApplyModal ref="modalForm" @ok="modalFormOk"></ErpHrTrainingApplyModal>
    <bpm-biz-task-deal-modal
      ref="taskDealModal"
      :path="path"
      :formData="formData"
      @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
    <process-config-modal ref="processConfig" @ok="handleSuccess" @close="handleClose"></process-config-modal>
    <!-- 项目详情开始 -->
    <erp-project-report-modal ref="projectForm"></erp-project-report-modal>
    <!-- 项目详情结束 -->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
  import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
  import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
  import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
  import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep';
  import ErpHrTrainingApplyModal from './modules/ErpHrTrainingApplyModal'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
  import { getAction } from '@/api/manage'
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'

  export default {
    name: 'ErpPurchaseApplyInvitationList',
    mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpProjectReportModal,
      ErpHrTrainingApplyModal,
      BpmBizTaskDealModal,
      BpmProcessTrackModal,
      BizTaskNotifyModal,
      BizTaskNotifyMeModal,
      SelectTeamInput,
      ProcessConfigModal,
      SelectUserByDep
    },
    data () {
      return {
        description: '培训申请单管理页面',
        // 表头
        columns: [],
        // 列设置
        settingColumns: [],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '单据编号',
            align: 'center',
            dataIndex: 'billNo',
            scopedSlots: { customRender: 'billNo' },
            width: 200,
            ellipsis: true
          },
          {
            title: '类型',
            align: 'center',
            width: 200,
            dataIndex: 'trainingType',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['trainingType'], text + '')
              }
            },
            ellipsis: true
          },
          {
            title: '申请人',
            align: 'center',
            dataIndex: 'handlerId',
            width: 100,
            ellipsis: true,
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['handlerId'], text + '')
              }
            }
          },
          {
            title: '申请部门',
            align: 'center',
            dataIndex: 'applyDeptId',
            width: 270,
            ellipsis: true,
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['applyDeptId'], text + '')
              }
            }
          },
          {
            title: '申请时间',
            align: 'center',
            dataIndex: 'createTime',
            width: 230,
            ellipsis: true
          },
          {
            title: '培训开始日期',
            align: 'center',
            dataIndex: 'trainingStartDate',
            width: 140,
            ellipsis: true
          },
          {
            title: '培训结束日期',
            align: 'center',
            dataIndex: 'trainingEndDate',
            width: 140,
            ellipsis: true
          },
          {
            title: '取得证书名称',
            align: 'center',
            dataIndex: 'certificateName',
            width: 170,
            ellipsis: true
          },
          {
            title: '流程状态',
            align: 'center',
            dataIndex: 'bpmStatus',
            width: 100,
            ellipsis: true,
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['bpmStatus'], text + '')
              }
            }
          },
          // {
          //   title: '单据状态',
          //   align: 'center',
          //   dataIndex: 'billStatus_dictText',
          //   width: 100,
          //   ellipsis: true
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 200,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: '/api/erp/hr/training/erpHrTrainingApply/list',
          delete: '/api/erp/hr/training/erpHrTrainingApply/delete',
          deleteBatch: '/api/erp/hr/training/erpHrTrainingApply/deleteBatch',
          exportXlsUrl: '/api/erp/hr/training/erpHrTrainingApply/exportXls',
          importExcelUrl: '/api/erp/hr/training/erpHrTrainingDetail/importExcel',
          bizCount: '/api/erp/hr/training/erpHrTrainingApply/bizCount',
          queryByProjectId: '/api/erp/project/report/erpProjectReport/queryById'
        },
        // 代码生成后需手动设置流程编码
        flowCode: 'dev_erp_hr_training_apply_001',
        formUrl: '/erp/hr/training/modules/ErpHrTrainingApplyForm',
        beanName: 'erpHrTrainingApplyServiceImpl',
        formUrlMobile: '/pages/synergy/ErpHrTrainingApplyList',
        dictOptions: {},
        superFieldList: [],
        processId: ''
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      handleRevoked() {
        this.$refs.modalForm.add('cancel');
        this.$refs.modalForm.title = '作废';
        this.$refs.modalForm.disableSubmit = false;
      },
      handleChange() {
        this.$refs.modalForm.add('change');
        this.$refs.modalForm.title = '变更';
        this.$refs.modalForm.disableSubmit = false;
      },
      beginProcess(record) {
        this.$refs.processConfig.visible = true
        this.$refs.processConfig.formUrl = this.formUrl
        this.$refs.processConfig.formUrlMobile = this.formUrlMobile
        this.$refs.processConfig.flowCode = this.flowCode
        this.$refs.processConfig.edit(record, this.processId, this.beanName)
      },
      handleSuccess() {
        this.loadData();
        this.$refs.modalForm.handleCancel()
        this.onClearSelected();
      },
      // 流程审批结束禁用
      getCheckboxProps(record) {
        return {
          props: {
            disabled: record.bpmStatus !== '1'
          }
        }
      },
      // 查看详情
      getDetail(id) {
        this.$router.push({
          path: `/erp/hr/training/ErpHrTrainingApplyListDetail/${id}`
        })
      },
      initDictConfig() {
        // // 关联项目
        // 姓名
        initDictOptions('erp_employee_file,name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'handlerId', res.result)
          }
        })
        // 部门
        initDictOptions('sys_depart,depart_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'applyDeptId', res.result)
          }
        })
        // 招标方式
        initDictOptions('training_type').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'trainingType', res.result)
          }
        })
        // 流程状态
        initDictOptions('bpm_status').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'bpmStatus', res.result)
          }
        })
      },
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'proposer', text: '申请人编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'billNo', text: '单据编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'applicant', text: '申请单位', dictCode: '' })
        fieldList.push({ type: 'string', value: 'employeeId', text: '申请人', dictCode: '' })
        fieldList.push({ type: 'string', value: 'departId', text: '申请部门', dictCode: '' })
        fieldList.push({ type: 'string', value: 'projectId', text: '关联项目', dictCode: '' })
        fieldList.push({ type: 'string', value: 'projectType', text: '关联项目类型', dictCode: '' })
        fieldList.push({ type: 'BigDecimal', value: 'projectBudget', text: '项目预算', dictCode: '' })
        fieldList.push({ type: 'string', value: 'teamId', text: '关联团队', dictCode: '' })
        fieldList.push({ type: 'string', value: 'payManner', text: '付款方式', dictCode: '' })
        // fieldList.push({ type: 'date', value: 'supplyTime', text: '工期(供货期)' })
        // 上线前完善 4 隐藏主表“项目类型”
        // fieldList.push({ type: 'string', value: 'projectGenre', text: '项目类型', dictCode: '' })
        fieldList.push({ type: 'string', value: 'invitationManner', text: '招标方式', dictCode: '' })
        fieldList.push({ type: 'date', value: 'expectUseTime', text: '期望到货时间' })
        fieldList.push({ type: 'string', value: 'provisionBroad', text: '采购大类', dictCode: '' })
        fieldList.push({ type: 'Text', value: 'description', text: '采购需求及项目描述', dictCode: '' })
        fieldList.push({ type: 'Text', value: 'remark', text: '备注', dictCode: '' })
        fieldList.push({ type: 'string', value: 'purchaseFile', text: '附件信息', dictCode: '' })
        fieldList.push({ type: 'string', value: 'bpmStatus', text: '流程状态', dictCode: '' })
        fieldList.push({ type: 'string', value: 'checkStatus', text: '流程审批结果', dictCode: '' })
        this.superFieldList = fieldList
      },
      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryByProjectId, { id: id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectForm.getDetail(model);
              that.$refs.projectForm.title = '项目一览表';
            }
          })
        })
      }
    }
  }
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
